﻿using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;

namespace Cloak.Mvp.Autofac
{
	/// <summary>
	/// Refers by type and name to a presenter which can be bound to a view
	/// </summary>
	public class NamedPresenterReference : PresenterReference
	{
		/// <summary>
		/// Initializes a reference to the specified presenter type with the specified name
		/// </summary>
		/// <param name="type">The type of presenter bound to the view</param>
		/// <param name="name">The name of the presenter bound to the view</param>
		public NamedPresenterReference(Type type, string name) : base(type)
		{
			Contract.Requires(name != null);

			Name = name;
		}

		/// <summary>
		/// Gets the name of the presenter bound to the view
		/// </summary>
		public string Name { get; private set; }

		/// <summary>
		/// Gets the site at which the view is bound to the presenter
		/// </summary>
		/// <param name="view">The view to which the presenter is bound</param>
		/// <returns>The site at which the view is bound to the presenter</returns>
		protected override PresenterSite GetSite(object view)
		{
			return new NamedPresenterSite(Type, Name, view);
		}
	}
}